package cn.edu.nankai.bookstore.service.impl;

import cn.edu.nankai.bookstore.dao.CustomerDao;
import cn.edu.nankai.bookstore.dao.impi.CustomerDaoImpl;
import cn.edu.nankai.bookstore.domain.po.Customer;
import cn.edu.nankai.bookstore.service.CustomerService;

import java.math.BigDecimal;
import java.util.List;

public class CustomerServiceImpl implements CustomerService {
    private CustomerDao customerDao = new CustomerDaoImpl();

    public boolean register(Customer customer){
        if(customerDao.findByTel(customer.getTelephone()) != null){
            return false;
        }
        return customerDao.insert(customer) != 0;
    }
    public Customer isValidate(String tel, String pwd){
        Customer customer = null;
        customer = customerDao.findByTel(new BigDecimal(tel));
        if(customer != null && customer.getPwd().equals(pwd)){
            return customer;
        }
        else{
            return null;
        }
    }
    public boolean modify(Customer customer){
        return customerDao.update(customer) != 0;
    }
    public List<Customer> getAll(){
        return customerDao.findAll();
    }
}
